#pragma once
#include "DBox.h"
#include "../DSpace.h"
#include "../DVector3.h"

namespace Skill
{
	namespace Ode
	{	
		namespace Geometries
		{
			void DBox::CollectManagedMemory()
			{
				_Lengths = nullptr;
				DGeometry::CollectManagedMemory();
			}
			DBox::DBox(DSpace^ space,dReal lx, dReal ly, dReal lz)
				:DGeometry(space)
			{
				dSpaceID s = space?space->_Space() : NULL;
				_SetPointer(dCreateBox(s, lx,ly,lz),true);
				if(_Container)
						_Container->AddSpace(this);
			}
			DBox::DBox(DSpace^ space,DVector3^ l)
				:DGeometry(space)
			{
				dSpaceID s = space?space->_Space() : NULL;
				_SetPointer(dCreateBox(s, l->_This[0],l->_This[1],l->_This[2]),true);
				if(_Container)
						_Container->AddSpace(this);
			}
			DVector3^ DBox::Lengths::get()
			{
				if(IsSpace)
					return nullptr;
				if(!_Lengths)
					_Lengths = gcnew DVector3();
				dGeomBoxGetLengths(_Geom(),_Lengths->_This);
				return _Lengths;
			}
			void DBox::Lengths::set(DVector3^ value)
			{
				if(IsSpace)
					return;
				dGeomBoxSetLengths(_Geom(),value->_This[0],value->_This[1],value->_This[2]);
			}

			dReal DBox::PointDepth(dReal x, dReal y, dReal z)
			{
				if(IsSpace) return System::Single::NaN;
				return dGeomBoxPointDepth(_Geom(),x,y,z);
			}
			dReal DBox::PointDepth(DVector3^ p)
			{
				if(IsSpace) return System::Single::NaN;
				return dGeomBoxPointDepth(_Geom(),p->_This[0],p->_This[1],p->_This[2]);
			}
		}
	}
}